package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.AdminOrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Api(tags = "分类相关接口")
@Slf4j
public class AdminOrderController {
    @Autowired
    private AdminOrderService adminOrderService;
    @GetMapping("/conditionSearch")
    @ApiOperation("商户订单管理")
    public Result<PageResult> orderListSearch(OrdersPageQueryDTO orderDto){
        return adminOrderService.selectOrderList(orderDto);
    }
    @GetMapping("/statistics")
    @ApiOperation("查询各种状态订单的数量")
    public Result<OrderStatisticsVO> selectOrderStatistics(){
       OrderStatisticsVO statisticsVO =  adminOrderService.selectStatistis();
        return Result.success(statisticsVO);
    }
    @GetMapping("/details/{orderId}")
    @ApiOperation("获取订单详情")
    public Result<OrderVO> getOrderInfo(@PathVariable Long orderId){
        return adminOrderService.selectOrderInfo(orderId);
    }
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        log.info("要取消的订单是：{}",ordersCancelDTO.getId());
        adminOrderService.cancel(ordersCancelDTO);
        return Result.success();
    }
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        adminOrderService.rejection(ordersRejectionDTO);
        return Result.success();
    }


}
